import url from 'url';
import { createRunner } from '@puppeteer/replay';

export async function run(extension) {
    const runner = await createRunner(extension);

    await runner.runBeforeAllSteps();

    await runner.runStep({
        type: 'setViewport',
        width: 1086,
        height: 739,
        deviceScaleFactor: 1,
        isMobile: false,
        hasTouch: false,
        isLandscape: false
    });
    await runner.runStep({
        type: 'navigate',
        url: 'http://192.168.17.150:8083/admin/login',
        assertedEvents: [
            {
                type: 'navigation',
                url: 'http://192.168.17.150:8083/admin/login',
                title: '登录'
            }
        ]
    });
    await runner.runStep({
        type: 'click',
        target: 'main',
        selectors: [
            [
                'aria/'
            ],
            [
                '#username'
            ],
            [
                'xpath///*[@id="username"]'
            ],
            [
                'pierce/#username'
            ]
        ],
        offsetY: 14,
        offsetX: 160.296875
    });
    await runner.runStep({
        type: 'change',
        value: 'mumulin',
        selectors: [
            [
                'aria/'
            ],
            [
                '#username'
            ],
            [
                'xpath///*[@id="username"]'
            ],
            [
                'pierce/#username'
            ]
        ],
        target: 'main'
    });
    await runner.runStep({
        type: 'change',
        value: 'h1058386570',
        selectors: [
            [
                'aria/'
            ],
            [
                '#password'
            ],
            [
                'xpath///*[@id="password"]'
            ],
            [
                'pierce/#password'
            ]
        ],
        target: 'main'
    });
    await runner.runStep({
        type: 'click',
        target: 'main',
        selectors: [
            [
                'aria/登 录'
            ],
            [
                'button'
            ],
            [
                'xpath///*[@id="app"]/div/div/div/div[2]/form/button'
            ],
            [
                'pierce/button'
            ],
            [
                'text/登 录'
            ]
        ],
        offsetY: 29,
        offsetX: 228.609375
    });

    await runner.runAfterAllSteps();
}

if (process && import.meta.url === url.pathToFileURL(process.argv[1]).href) {
    run()
}
